cmake_minimum_required(VERSION 3.4.1)

#设置生成的so动态库最后输出的路径
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/libs_export/${ANDROID_ABI})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/libs_export/${ANDROID_ABI})

#设置工程源码根目录
set(ToolKit_Root ${CMAKE_SOURCE_DIR}/3rdpart/src/ZLMediaKit/ZLToolKit/src)
set(MediaKit_Root ${CMAKE_SOURCE_DIR}/3rdpart/src/ZLMediaKit/src)
set(Sqlite_Root ${CMAKE_SOURCE_DIR}/3rdpart/src/sqlite)
set(ApiExport_Root ${CMAKE_SOURCE_DIR}/3rdpart/src/ZLMediaKit/c_wrapper/src)
set(JNI_Root ${CMAKE_SOURCE_DIR}/src/main/cpp)

#设置宏定义
add_definitions(-DENABLE_RING_USEBUF -DENABLE_OPENSSL -DENABLE_HLS -D_DEBUG)

#设置头文件目录
INCLUDE_DIRECTORIES(${ToolKit_Root})
INCLUDE_DIRECTORIES(${MediaKit_Root})
INCLUDE_DIRECTORIES(${Sqlite_Root})
INCLUDE_DIRECTORIES(${ApiExport_Root})

#第三方库路径
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/3rdpart/include/${ANDROID_ABI})
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/3rdpart/lib/${ANDROID_ABI})

#收集源代码
file(GLOB ToolKit_src_list ${ToolKit_Root}/*/*.cpp ${ToolKit_Root}/*/*.h ${ToolKit_Root}/*/*.c)
file(GLOB MediaKit_src_list ${MediaKit_Root}/*/*.cpp ${MediaKit_Root}/*/*.h ${MediaKit_Root}/*/*.c)
file(GLOB Sqlite_src_list ${Sqlite_Root}/*.cpp ${Sqlite_Root}/*.c ${Sqlite_Root}/*.h)
file(GLOB ApiExport_src_list ${ApiExport_Root}/*.cpp ${ApiExport_Root}/*.c ${ApiExport_Root}/*.h)
file(GLOB JNI_src_list ${JNI_Root}/*.cpp ${JNI_Root}/*.c ${JNI_Root}/*.h)

#去除win32的适配代码
list(REMOVE_ITEM ToolKit_src_list ${ToolKit_Root}/win32/getopt.c)

#添加库
add_library(zltoolkit STATIC ${ToolKit_src_list})
add_library(zlmediakit STATIC ${MediaKit_src_list})
add_library(sqlite3 STATIC ${Sqlite_src_list})
add_library(apiexport STATIC ${ApiExport_src_list})
add_library(mediajni SHARED ${JNI_src_list})

#libz liblog ...
set(LINK_LIB_LIST curl ssl crypto log z)

#连接动态库
target_link_libraries(mediajni apiexport sqlite3 zlmediakit zltoolkit ${LINK_LIB_LIST})